-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent logging all the JSDOM internal errors. #5267
Conversation
@kentcdodds thoughts on this? |
The failing tests that are shown here, ran locally without failing. I'm on |
I decided to not use
Because #5227, the console JSDOM uses is the same one you have in your tests, so it's mockable now. So if you don't like the errors that are logged, you can simply do: beforeEach(() => {
jest.spyOn(console, 'error')
console.error.mockImplementation(() => {})
})
afterEach(() => {
console.error.mockRestore()
}) So I would recommend against making this change. |
Thanks Kent. I agree. @Aftabnack thanks for sending a pull request and I hope you'll understand that we do not want to merge it at this time. If you feel strongly, you can create your own test environment with this configuration as a default. |
|
FWIW, the error stack trace in the screenshot on that README is indicative of an actual problem. It looks like This is why I recommend against making this change. Otherwise you will miss these valuable indicative errors. |
@kentcdodds Appreciate you taking time out for this.
|
Yeah. What I would do is provide my own implemention/switch it to use location.assign and mock that 👍 |
That actually makes more sense. Something like this? import changeHref from '../common';
doDownload() {
changeHref(myUrl);
}
|
No, I mean in your source code use location.assign instead of assigning to location.herf, then spyOn location.assign with a mock implemention (similar to my console.error mock above). |
@kentcdodds I was going over this again while writing testcases, I began to wonder. My code that I have written is expected to run on latest browsers (Firefox/Chrome) which have these sort of functionality. So I shouldn't be changing my code just to make it run on jest. Thoughts? |
I agree with you philosophically, but the fact of the matter is that those APIs are not supported by jsdom. You could try to implement them yourself if you like. I do that with Good luck! |
Where is PS: I've mocked localStorage and sessionStorage too. |
There is a jest-env-webdriver 😉 |
Cool I'll try it out!! |
If you don't want to change your code to use delete window.location;
window.location = {}; // or stub/spy etc. |
I'm pretty sure that JSDOM 12 added support for |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Test plan
Not sure what to do for this.